package org.haredot.controller;

import org.haredot.annotation.LogModule;
import org.haredot.entity.ServiceLog;
import org.haredot.service.LoggerService;
import org.haredot.vo.PageVo;
import org.haredot.vo.ResultVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/log")
public class LoggerController {

    @Resource
    private LoggerService loggerService ;

    @GetMapping("/service/list")
    @PreAuthorize("hasAuthority('service:log')")
    public ResultVo<?> serviceList(@RequestParam("page")Integer page,
                                   @RequestParam("limits") Integer limits,
                                   @RequestParam Map<String, ?> params) {
        // 接收页面参数
        PageVo<ServiceLog> pageVo = new PageVo<>(page, limits);
        // 设置查询参数
        pageVo.setParams(params);

        return loggerService.queryServiceLogs(pageVo);
    }

    @GetMapping("/log/list")
    @PreAuthorize("hasAuthority('login:log')")
    public ResultVo<?> loginLogList(@RequestParam("page")Integer page,
                                   @RequestParam("limits") Integer limits,
                                   @RequestParam Map<String, ?> params) {
        // 接收页面参数
        PageVo<ServiceLog> pageVo = new PageVo<>(page, limits);
        // 设置查询参数
        pageVo.setParams(params);

        return loggerService.queryLoginLogs(pageVo);
    }
}
